home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / c01lab4.zip / LRMRDR / LRM_TEST.ZIP / STATS.A next >
Text File  |  1992-05-29  |  6KB  |  175 lines

  1. -- Stats by Richard Conn
  2. -- Scan Ada LRM Chapter Files and generate information on their
  3. -- attributes, sending the results to standard output.
  4. -- Stats is a part of the Ada LRM Reader.
  5.  
  6. -- ***********************************************************************
  7. -- ON-LINE Ada LANGUAGE REFERENCE MANUAL by Richard Conn
  8. --
  9. -- COPYRIGHT NOTICE
  10. -- Ada LRM Reader - Interactive Presentation of the Ada LRM
  11. -- Copyright (C) 1992    Richard Conn
  12. --
  13. -- This program is free software; you can redistribute it
  14. -- and/or modify it under the terms of the GNU General Public
  15. -- License Version 1 as published by the Free Software
  16. -- Foundation.
  17. --
  18. -- This program is distributed in the hope that it will be
  19. -- useful, but WITHOUT ANY WARRANTY; without even the implied
  20. -- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  21. -- PURPOSE.  See the GNU General Public License for more
  22. -- details.  You should have received a copy of the GNU General
  23. -- Public License along with this program; if not, write to the
  24. -- Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
  25. -- 02139, USA.  See the ABOUT screens for further information,
  26. -- including information on how to contact the author.
  27.  
  28. with Console;     -- CS Parts
  29. with Input_File;  -- CS Parts
  30. procedure Stats is
  31.  
  32.   subtype FN_STRING is STRING(1..10);
  33.   type FN_VECTOR is array (NATURAL range <>) of FN_STRING;
  34.   File_Names : constant FN_VECTOR := (
  35.     "chap01.doc", "chap02.doc", "chap03.doc", "chap04.doc",
  36.     "chap05.doc", "chap06.doc", "chap07.doc", "chap08.doc",
  37.     "chap09.doc", "chap10.doc", "chap11.doc", "chap12.doc",
  38.     "chap13.doc", "chap14.doc", "chapaa.doc", "chapab.doc",
  39.     "chapac.doc", "chapad.doc", "chapae.doc", "chapaf.doc",
  40.     "chapco.doc", "chapfo.doc", "chapin.doc", "chappo.doc",
  41.     "chaphe.doc", "chapxx.doc"
  42.     );
  43.  
  44.   Input_File_ID         : Input_File.FILE_TYPE;
  45.   Max_Input_Line_Length : constant := 200;
  46.  
  47.   Inline      : STRING (1..Max_Input_Line_Length);
  48.   Inlast      : NATURAL;
  49.   Start       : NATURAL;
  50.   Stop        : NATURAL;
  51.  
  52.   Global_Largest_Number_of_Sections : NATURAL := 0;
  53.   Global_Longest_Line               : NATURAL := 0;
  54.   Global_Longest_Section            : NATURAL := 0;
  55.   Global_Line_Number                : NATURAL := 0;
  56.  
  57.   File_Number                       : NATURAL := 0;
  58.  
  59.   Total_Number_of_Sections          : NATURAL := 0;
  60.   Total_Number_of_Lines             : NATURAL := 0;
  61.  
  62.   ----------------------------------------------------------------
  63.   -- Generate statistics on a particular file.
  64.   procedure Process_File (Name : in STRING) is
  65.     Lines_per_Section  : NATURAL := 0;
  66.     Longest_Section    : NATURAL := 0;
  67.     Longest_Line       : NATURAL := 0;
  68.     Line_Number        : NATURAL := 0;
  69.     Number_of_Sections : NATURAL := 0;
  70.   begin
  71.  
  72.     Input_File.Open (Input_File_ID, Name);
  73.     File_Number := File_Number + 1;
  74.  
  75.     -- Pass over file, collecting statistics
  76.     while not Input_File.End_of_File (Input_File_ID) loop
  77.       Input_File.Get_Line (Input_File_ID, Inline, Inlast);
  78.       if Inlast > Longest_Line then
  79.         Longest_Line := Inlast;
  80.       end if;
  81.       Line_Number := Line_Number + 1;
  82.       Lines_per_Section  := Lines_per_Section + 1;
  83.       if Inlast > 2 and then Inline(1..2) = "> " then
  84.         Number_of_Sections := Number_of_Sections + 1;
  85.         Lines_per_Section  := Lines_per_Section  - 1;
  86.         if Lines_per_Section > Global_Longest_Section then
  87.           Global_Longest_Section := Lines_per_Section;
  88.         end if;
  89.         if Lines_per_Section > Longest_Section then
  90.           Longest_Section := Lines_per_Section;
  91.         end if;
  92.         Lines_per_Section := 1;
  93.       end if;
  94.     end loop;
  95.  
  96.     -- Update the global data on the longest items
  97.     if Longest_Line > Global_Longest_Line then
  98.       Global_Longest_Line := Longest_Line;
  99.     end if;
  100.     if Lines_per_Section > Global_Longest_Section then
  101.       Global_Longest_Section := Lines_per_Section;
  102.     end if;
  103.     if Lines_per_Section > Longest_Section then
  104.       Longest_Section := Lines_per_Section;
  105.     end if;
  106.     if Line_Number > Global_Line_Number then
  107.       Global_Line_Number := Line_Number;
  108.     end if;
  109.     if Number_of_Sections > Global_Largest_Number_of_Sections then
  110.       Global_Largest_Number_of_Sections := Number_of_Sections;
  111.     end if;
  112.  
  113.     -- Update the global data on the totals
  114.     Total_Number_of_Sections := Total_Number_of_Sections +
  115.                                 Number_of_Sections;
  116.     Total_Number_of_Lines    := Total_Number_of_Lines +
  117.                                 Line_Number;
  118.  
  119.     Input_File.Close (Input_File_ID);
  120.  
  121.     -- Display data accumulated for the current file
  122.     Console.Put (File_Number, 2);
  123.     Console.Put (". " & Name);
  124.     Console.Put (Line_Number, 6);
  125.     Console.Put (Number_of_Sections, 6);
  126.     Console.Put (Longest_Section, 6);
  127.     Console.Put (Longest_Line, 6);
  128.     Console.New_Line;
  129.  
  130.   exception
  131.     when others =>
  132.       Console.Put_Line ("Error on File " & Name);
  133.   end Process_File;
  134.  
  135.   procedure Print_Header (First_Header : in STRING) is
  136.   begin
  137.     Console.Put (First_Header);
  138.     Console.Put (" Lines");
  139.     Console.Put (" Sects");
  140.     Console.Put ("  Slen");
  141.     Console.Put ("  LLen");
  142.     Console.New_Line;
  143.   end Print_Header;
  144.  
  145. begin -- Make_CIT
  146.  
  147.   Print_Header ("    File Name ");
  148.  
  149.   -- Build chapters.idx file
  150.   for I in File_Names'RANGE loop
  151.     Process_File (File_Names(I));
  152.   end loop;
  153.  
  154.   Console.New_Line;
  155.   Print_Header ("              ");
  156.  
  157.   -- Display data on the longest/largest values
  158.   Console.Put ("Longest =>    ");
  159.   Console.Put (Global_Line_Number, 6);
  160.   Console.Put (Global_Largest_Number_of_Sections, 6);
  161.   Console.Put (Global_Longest_Section, 6);
  162.   Console.Put (Global_Longest_Line, 6);
  163.   Console.New_Line;
  164.  
  165.   -- Display data on the totals
  166.   Console.New_Line;
  167.   Console.Put ("Total Lines    =>");
  168.   Console.Put (Total_Number_of_Lines, 6);
  169.   Console.New_Line;
  170.   Console.Put ("Total Sections =>");
  171.   Console.Put (Total_Number_of_Sections, 6);
  172.   Console.New_Line;
  173.  
  174. end Stats;
  175.